package com.stox.charting.ui.swing.presenter.delegate.advisor;

import java.awt.Dimension;

import com.stox.charting.ui.swing.view.ChartingInternalFrameView;
import com.stox.navigator.ui.swing.view.NavigatorView;

public class ChartingInternalFrameViewSizeAdvisor {

	private ChartViewSizeAdvisor chartViewSizeAdvisor;
	private NavigatorView navigatorView;
	
	public void advise(ChartingInternalFrameView chartingInternalFrameView,
			int count, int index, int rows, int columns){
		if(chartingInternalFrameView != null){
			int width = chartingInternalFrameView.getParent().getSize().width;
			int height = chartingInternalFrameView.getParent().getSize().height;
			int x = navigatorView.getSize().width + navigatorView.getLocation().x;

			if(navigatorView != null && navigatorView.isVisible()
					&& chartingInternalFrameView.getParent().getSize().width > x*2){
				width = chartingInternalFrameView.getParent().getSize().width - x;
				height = chartingInternalFrameView.getParent().getSize().height;
			}
			
			height = height/rows;
			width = width/columns;
			if(index == count){
				width += ((rows*columns)-index)*width;
			}
			chartingInternalFrameView.setSize(new Dimension(width, height));
			chartViewSizeAdvisor.advise(chartingInternalFrameView.getPriceChartView());
		}
		
	}

	public void setChartViewSizeAdvisor(ChartViewSizeAdvisor chartViewSizeAdvisor) {
		this.chartViewSizeAdvisor = chartViewSizeAdvisor;
	}

	public void setNavigatorView(NavigatorView navigatorView) {
		this.navigatorView = navigatorView;
	}
	
}
